﻿using Library.Core.Domain.Specification;
using Synthesize.BaseSet.Domain.Aggregation.Entity.Authority;
using System;
using System.Linq.Expressions;

namespace Synthesize.BaseSet.Domain.Specifications.Authority.Department
{

    /// <summary>
    /// 部门查询条件拼装
    /// </summary>
    public class GetDepartmentListSpceification : ISpecification<DepartmentInfoEntity>
    {
        private readonly string _name;
        private readonly Guid? _id;


        public GetDepartmentListSpceification(string name)
        {
            _name = name;
        }
        public GetDepartmentListSpceification(string name, Guid? id)

        {
            _name = name;
            _id = id;
        }
        public Expression<Func<DepartmentInfoEntity, bool>> SatisfiedBy()
        {
            Specification<DepartmentInfoEntity> spec = new TrueSpecification<DepartmentInfoEntity>();

            if (!string.IsNullOrEmpty(_name))
            {
                spec &= new DirectSpecification<DepartmentInfoEntity>(x => x.Name.Contains(_name.Trim()));
            }
            if (_id.HasValue)
            {
                spec &= new DirectSpecification<DepartmentInfoEntity>(x => x.Id == _id);
            }
            return spec.SatisfiedBy();
        }
    }
}
